from collections import Counter


class Solution:
    def frequencySort(self, s: str) -> str:
        c = dict(Counter(s))
        s_td = sorted(c.items(), key=lambda x: -x[1])
        s = ""
        for key, value in s_td:
            s = s + key * value
        return s


if __name__ == '__main__':
    s = Solution()
    r = s.frequencySort("tree")
    print(r)
